package com.atguigu02._class;

import org.junit.Test;

import java.sql.SQLOutput;

/**
 * ClassName: GetClass
 * Package: com.atguigu02._class
 * Description:
 *
 * @Author BuTang
 * @Create 2023/6/25 9:26
 * @Version 1.0
 */
public class GetClass {
    @Test
    public void test() throws ClassNotFoundException {

        //方法1，直接使用类.class
        Class clazz = User.class;
        System.out.println(clazz);

        //方法2:使用对象.getclass
        User u = new User("张",22);
        Class clazz1 = u.getClass();
        System.out.println(clazz1);

        //方法3:使用class.forname
        Class clazz2 = Class.forName("com.atguigu02._class.User");
        System.out.println(clazz2);

        //方法4：使用类的加载器
        Class clazz3 = ClassLoader.getSystemClassLoader().loadClass("com.atguigu02._class.User");
        System.out.println(clazz3);

    }

}
